home *** CD-ROM | disk | FTP | other *** search
/ JCSM Shareware Collection 1993 November / JCSM Shareware Collection - 1993-11.iso / cl720 / sst115j.lzh / SSTMOU.C < prev    next >
C/C++ Source or Header  |  1992-08-01  |  7KB  |  208 lines

  1. /* ------------------------------------------------------------------------ */
  2. /*                                sstmouse.c                                */
  3. /*                         low-level mouse routines                         */
  4. /*                                                                          */
  5. /*      CopyRight (C) 1991,1992  Steven Lutrov.   All rights reserved.      */
  6. /* ------------------------------------------------------------------------ */
  7. #include <stdio.h>
  8. #include <dos.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11.  
  12. #include "sstvid.h"
  13. #include "sstmou.h"
  14.  
  15. /* ------------------------------------------------------------------------ */
  16. /*                               timer macros                               */
  17. /* ------------------------------------------------------------------------ */
  18. #define timedout(timer)          (timer==0)
  19. #define settimer(timer, secs)    timer=(secs)*182/10+1
  20. #define timerdisabled(timer)     (timer == -1)
  21. #define disabletimer(timer)      timer = -1
  22. #define timerrunning(timer)      (timer > 0)
  23. #define countdown(timer)         --timer
  24.  
  25. #define TIMER                  8
  26. #define DOUBLETICKS            5
  27.  
  28.  
  29. int sstmoused = 0;
  30. int swidth = SCREENWIDTH;
  31.  
  32. /* ------------------------------------------------------------------------ */
  33. /*                        local function prototypes                         */
  34. /* ------------------------------------------------------------------------ */
  35. static void near mouse     (int m1,int m2,int m3,int m4);
  36. static void (interrupt far *oldtimer)(void);  /* set interrupt handler */
  37.  
  38.  
  39. /* ------------------------------------------------------------------------ */
  40. /*                              local variables                             */
  41. /* ------------------------------------------------------------------------ */
  42. static int msclicktimer = -1;                 /* set to clear timer */
  43.  
  44.  
  45. /* ------------------------------------------------------------------------ */
  46. /*            main mouse interrupt routine used by other functions          */
  47. /* ------------------------------------------------------------------------ */
  48. static void near mouse(int m1,int m2,int m3,int m4)
  49. {
  50.     _DX = m4;
  51.     _CX = m3;
  52.     _BX = m2;
  53.     _AX = m1;
  54.     geninterrupt(MOUSE);
  55. }
  56.  
  57. /* ------------------------------------------------------------------------ */
  58. /*                             reset the mouse                              */
  59. /* ------------------------------------------------------------------------ */
  60. void msreset(void)
  61. {
  62.     mouse(0,0,0,0);
  63. }
  64.  
  65. /* ------------------------------------------------------------------------ */
  66. /*                 test to see if the mouse driver is installed             */
  67. /* ------------------------------------------------------------------------ */
  68. int msinstalled(void)
  69. {
  70.     unsigned char far *ms;
  71.  
  72.     ms = MK_FP(peek(0, MOUSE*4+2), peek(0, MOUSE*4));
  73.     return  (swidth <= 80 && ms != NULL && *ms != 0xCF);
  74. }
  75.  
  76. /* ------------------------------------------------------------------------ */
  77. /*                  return true if mouse buttons are pressed                */
  78. /* ------------------------------------------------------------------------ */
  79. int mspressed(void)
  80. {
  81.     if (msinstalled())
  82.         mouse(3,0,0,0);
  83.     return _BX & 3;
  84. }
  85.  
  86. /* ------------------------------------------------------------------------ */
  87. /*                          return mouse coordinates                        */
  88. /* ------------------------------------------------------------------------ */
  89. void msgetpos(int *x, int *y)
  90. {
  91.     if (msinstalled())    {
  92.         mouse(3,0,0,0);
  93.     *x = _CX / 8;
  94.     *y = _DX / 8;
  95.         if (swidth == 40)
  96.             *x /= 2;
  97.     }
  98. }
  99.  
  100. /* ------------------------------------------------------------------------ */
  101. /*                         position the mouse cursor                        */
  102. /* ------------------------------------------------------------------------ */
  103. void mssetpos(int x, int y)
  104. {
  105.     if (msinstalled())    {
  106.         if (swidth == 40)
  107.             x *= 2;
  108.         mouse(4,0,x*8,y*8);
  109.     }
  110. }
  111.  
  112. /* ------------------------------------------------------------------------ */
  113. /*                          display the mouse cursor                        */
  114. /* ------------------------------------------------------------------------ */
  115. void msshow(void)
  116. {
  117.     if (msinstalled())
  118.         mouse(1,0,0,0);
  119. }
  120.  
  121. /* ------------------------------------------------------------------------ */
  122. /*                           hide the mouse cursor                          */
  123. /* ------------------------------------------------------------------------ */
  124. void mshide(void)
  125. {
  126.     if (msinstalled())
  127.         mouse(2,0,0,0);
  128. }
  129.  
  130. /* ------------------------------------------------------------------------ */
  131. /*               return true if a mouse button has been released            */
  132. /* ------------------------------------------------------------------------ */
  133. int msreleased(void)
  134. {
  135.     if (msinstalled())
  136.         mouse(6,0,0,0);
  137.     return _BX;
  138. }
  139.  
  140. /* ------------------------------------------------------------------------ */
  141. /*                          set mouse travel limits                         */
  142. /* ------------------------------------------------------------------------ */
  143. void mssettravel(int minx, int maxx, int miny, int maxy)
  144. {
  145.     if (msinstalled())    {
  146.         if (swidth == 40)    {
  147.             minx *= 2;
  148.             maxx *= 2;
  149.         }
  150.         mouse(7, 0, minx*8, maxx*8);
  151.         mouse(8, 0, miny*8, maxy*8);
  152.     }
  153. }
  154.  
  155. /* ------------------------------------------------------------------------ */
  156. /*                       timer interrupt service routine                    */
  157. /* ------------------------------------------------------------------------ */
  158. static void interrupt far newtimer(void)
  159. {
  160.     if (timerrunning(msclicktimer))
  161.     countdown(msclicktimer);
  162.     oldtimer();
  163. }
  164.  
  165. /* ------------------------------------------------------------------------ */
  166. /*                   test if left button was double pressed                 */
  167. /* ------------------------------------------------------------------------ */
  168. int msdleftpressed(void)
  169.  
  170. {
  171.     if (oldtimer == NULL)    {
  172.     oldtimer = getvect(TIMER);
  173.     setvect(TIMER, newtimer);
  174.     }
  175.     if (msreleased())
  176.       msclicktimer = DOUBLETICKS;
  177.     if (msleftpressed())    {
  178.         if (timerrunning(msclicktimer))    {
  179.         disabletimer(msclicktimer);
  180.         return (1);
  181.           }
  182.     }
  183.  return(0);
  184. }
  185. /* ------------------------------------------------------------------------ */
  186. /*                   test if right button was double pressed                */
  187. /* ------------------------------------------------------------------------ */
  188. int msdrightpressed(void)
  189.  
  190. {
  191.     if (oldtimer == NULL)    {
  192.     oldtimer = getvect(TIMER);
  193.     setvect(TIMER, newtimer);
  194.     }
  195.     if (msreleased())
  196.       msclicktimer = DOUBLETICKS;
  197.     if (msrightpressed())    {
  198.         if (timerrunning(msclicktimer))    {
  199.         disabletimer(msclicktimer);
  200.         return (1);
  201.           }
  202.     }
  203.  return(0);
  204. }
  205.  
  206.  
  207.  
  208.